package com.ms.tank.abstractfactory;

import com.ms.tank.common.ResourceManager;
import com.ms.tank.game.TankFrame;
import com.ms.tank.utils.Audio;

import java.awt.*;

/**
 * @Date 2021/3/18 18:41:01
 * @Author mashuai
 */
public class RectExplode extends BaseExplode {
    public static int WIDTH = ResourceManager.explodes[0].getWidth();
    public static int HEIGHT = ResourceManager.explodes[0].getHeight();
    public TankFrame tankFrame = null;
    private int step = 0;
    private int x, y;

    public RectExplode(TankFrame tankFrame, int x, int y) {
        this.tankFrame = tankFrame;
        this.x = x;
        this.y = y;
        new Thread(() -> new Audio("audio/explode.wav").play()).start();
    }

    @Override
    public void paint(Graphics graphics) {
        Color c = graphics.getColor();
        graphics.setColor(Color.RED);
        graphics.fillRect(x, y, 10 * step, 10 * step);
        step++;

        if (step >= 15){
            tankFrame.explodes.remove(this);
        }

        graphics.setColor(c);

    }
}
